31. Practice Question

Practice Question

For the following practice question you will need to write code in Python in the workspace below. This will allow you to practice the concepts discussed in the Scripting lesson, such as reading and writing files. You will see some older concepts too, but again, we have them there to review and reinforce your understanding of those concepts.

** Question: ** Create a function that opens the flowers.txt, reads every line in it, and saves it as a dictionary. The main (separate) function should take user input (user's first name and last name) and parse the user input to identify the first letter of the first name. It should then use it to print the flower name with the same first letter (from dictionary created in the first function).

Sample Output:

>>> Enter your First [space] Last name only: Bill Newman
>>> Unique flower name with the first letter: Bellflower

** Using this workspace**

We have provided a programming environment with a Terminal and code editor, so you can do all your work right here. Here are a few tips orienting you to this kind of workspace.

On the top panel is a code editor where you can edit the Python file ** match_lower_name.py**. Scroll up and down in this panel to see all the code. You can also expand or shrink this panel by clicking and dragging its bottom border. We have included the flower.txt file that includes the list of unique flower names for each alphabet. You can click on it in the left to open it in a new tab.

On the bottom panel, you can execute your Python file by clicking on New Terminal and entering ** python match_flower_name.py** on the command line.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: generic
  • Opened files (when workspace is loaded): n/a